import TimerBaseCommand from './timerBaseCommand';

class UpdateTimerCommand extends TimerBaseCommand {
  static CMD = 0x0A;  // 更新定时事件命令

  /**
   * 创建更新定时命令
   * @param {Object} config - 定时配置
   */
  static createCommand(config) {
    const timeData = this.packTimeData(config);
    const data = new Uint8Array(timeData.length + 1);
    data[0] = config.timerId;
    data.set(timeData, 1);
    return this.packFrame(this.CMD, data);
  }

  /**
   * 解析更新定时响应
   * @param {Uint8Array} frame - 响应数据帧
   */
  static parseResponse(frame) {
    const parsed = this.parseBaseFrame(frame);
    if (!parsed || parsed.cmd !== this.CMD) return null;

    return {
      success: parsed.data[0] === 1
    };
  }
}

export default UpdateTimerCommand; 